

cat << EOF > $K8_CONFIG_HOME/kube-controller-manager

KUBE_CONTROLLER_MANAGER_OPTS="--logtostderr=true \
    --v=4 \
    --master=127.0.0.1:8080 \
    --leader-elect=true \
    --address=127.0.0.1 \
    --service-cluster-ip-range=$K8_SERVICE_CLUSTER_IP_RANGE \
    --cluster-name=kubernetes \
    --cluster-signing-cert-file=$K8_CERT_HOME/kube-ca.pem \
    --cluster-signing-key-file=$K8_CERT_HOME/kube-ca-key.pem  \
    --root-ca-file=$K8_CERT_HOME/kube-ca.pem \
    --service-account-private-key-file=$K8_CERT_HOME/kube-ca-key.pem"


EOF


currentPath=$(pwd)

cat << EOF > $currentPath/build/service/kube-controller-manager.service

[Unit]
Description=Kubernetes Controller Manager
Documentation=https://github.com/kubernetes/kubernetes
 
[Service]
EnvironmentFile=$K8_CONFIG_HOME/kube-controller-manager
ExecStart=$K8_SERVER_BIN/kube-controller-manager \$KUBE_CONTROLLER_MANAGER_OPTS
Restart=on-failure
 
[Install]
WantedBy=multi-user.target

EOF

sed -i '/kube-controller-manager/d' $K8_MASTER_SHELL
sed -i "/daemon-reload/i\cp $currentPath/build/service/kube-controller-manager.service $K8_SERVICE_HOME/" $K8_MASTER_SHELL

echo "systemctl enable kube-controller-manager " >> $K8_MASTER_SHELL
echo "systemctl stop kube-controller-manager " >> $K8_MASTER_SHELL
echo "systemctl start kube-controller-manager " >> $K8_MASTER_SHELL


checkShell=$currentPath/build/master-check.sh
echo "#check master " > $checkShell
chmod +x $checkShell

echo "$K8_CLIENT_BIN/kubectl get cs,nodes" >> $checkShell
